package ioc13;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.*;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/5/17 10:26
 * Version:1.0-SNAPSHOT
 * Description:
 */
public class Test {

    public static void main(String[] args) throws IOException {
        // File file = new File("ioc13/a.txt");
        // Resource resource = new ClassPathResource("ioc13/a.txt");
        // File file = resource.getFile();

//        InputStream in = resource.getInputStream();
//        BufferedReader br = new BufferedReader(new InputStreamReader(in));
//        System.out.println(br.readLine());

        ApplicationContext ac = new ClassPathXmlApplicationContext("ioc13/spring.xml");
        // 当解析对应的XML之后
        // 我们除了可以使用解析后获取的bean以外
        // Spring也提供一些对应的常用功能
        // 例如:可以获取到对应的Resource对象
        // 获取Resource对象时,需要指定获取的是哪一个文件所对应的对象
        // 因此,其方法的参数为文件的路径
        // 相当于new ClassPathResource(path)中的参数path
        // Resource resource = ac.getResource("ioc13/a.txt");

        SomeBean someBean = (SomeBean) ac.getBean("someBean");
        Resource resource = someBean.getResource();

        InputStream in = resource.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        System.out.println(br.readLine());
    }

}
